{%- macro main_menu(data,hierarchy) %}
    {% for key, value in hierarchy %}
        <li>
            <a href="{{ url(data[key]['href']) }}">{{ data[key]['name'] }}
                {% if key != value %}
                    <i aria-hidden="true" class="icon-caret-down"></i>
                {% endif %}
            </a>
            {% if key != value %}
                <ul class="sub-menu">
                    {{ main_menu(data,value) }}
                </ul>
            {% endif %}
        </li>
    {% endfor %}
{%- endmacro %}
<ul class="menu">
    {{ main_menu(data,hierarchy) }}
</ul>